![]() |
||||||||||||||||||||||||
SNAP - 04: BOOLEAN and VARIABLES OPENING QUESTIONS: What do we mean by the term "Boolean?" Why is it essential to computer programming?
OBJECTIVE: I will be able to write simple boolean code during today's class. WORD FOR TODAY:
WORK O' THE DAY: Remember, computers are nothing more than high speed idiots. As such, computers work best when processing information that is either true (1) or false (0) When writing computer code, it is frequently helpful to think like and program for, a computer. As such, we have 3 different 'boolean operators' that we need to get a handle on: AND, OR, NOT In order for an AND statement to be true, each part of the operation in question MUST be true. Let's take a look at a fun sorta weather analogy to talk about BOOLEAN operators. It might be raining outside, it might also be windy outside and it might also be windy AND rainy outside. Is it raining outside AND is it windy outside gives us two items to compare:
Let's break that down. Let's say we look out the window and we determine that yes, it is raining but no, it is not windy. That gives us the following data:
Now let's evaluate those together using the AND Statement:
Since those two statements are linked by an AND statement, the computer evaluates both to see if both statements are True. If they are, the computer will return a True. Any other situation returns False Therefore:
Soooooo, the takeway here is that ALL statements connected by an AND must be true in order for the computer to evaluate that as true. ANY presence of false will return False. USING AND
The OR operator is a bit easier to get used to. The OR operator basically checks to see if EITHER expression is true. If either expression is true the command returns true:
═══════════════════ The NOT operator The NOT operator can be a bit tricky at times. The NOT operator checks to see if the reverse of <whatever the statement is> is true. If the reverse of the <whatever statement> is true, the NOT operator returns true: For example let's take a look at our rain question again: Is it (NOT) (raining outside today) If (raining outside today) = true then let's subsitute True in for our statement that we are evaluating: (NOT) (TRUE) and we all know that not true = FALSE so in that case: Is it (NOT) (raining outside today) = FALSE However, let's re-evaluate for the case where it is NOT raining outside: Let's start with our initial statement Is it (NOT) (raining outside today) it isn't raining outside today so (raining outside today) = False NOT (False) and NOT False = True! Whooo hooooo! Let's take a look at Lab 2.5
═══════════════════════════ HOMEWORK: |
||||||||||||||||||||||||